function x = get_data_to_excel(id_web,offset,ticker,type)

    url_string = 'http://ezsearch.fpts.com.vn/Services/EzData/ProcessLoadRuntime.aspx?s=%d&cGroup=Finance&cPath=Services/EzData/FinanceReport&ReportID=Rat&pd=4&fy=%d&cn=%d&un=1';        
    typeData='FI';
    
    x = 0;

    for y = 2012:-offset:2001
        current_year = y;  
        if(y~=2012)
            temp = [final_res{2:end,end}];
            if(all(temp=='-') || isempty(temp))
                break;
            end
        end
        final_res = [];        
        
        url = sprintf(url_string,id_web,current_year,offset*4);
        fprintf('\n    ... Fetching data %d',current_year);
%         urlText    = java.lang.String(urlread_1(url)); 
        temp = urlread(url);
        temp = regexprep(temp, 'body=\[<table>[^\]]*</table>\]','');
        urlText    = java.lang.String(temp);
        fprintf('... Done!');
        
                        
        k = 3;
        while(k < 101)
            try
               res = getTableFromHTML_mod(urlText,k);            
            catch exception
                break;
            end
            
            if(y ~= 2012)
                %skip the first column
                res(:,1)=[];    
                
            end
            if(size(res,2)==1)
                k=k+1;
                continue;                
            end
            if(size(res,1)>1)
                x =-1;
                return;     
            end
            final_res = [final_res; res];
            
            
%             xlswrite(sprintf('data\%d_%s_%d_%d.xls',type,text{j+1,1},ndata(j,1),current_year)...
%             , res, sprintf('A%d',k));                                        

            k = k+1;
        end
        fprintf('\n    ... Writing to excel ...');        
        if(y==2012)
            range = 'A1';
        else
            temp = 'B'+(2012-y)*4;
            str = char(temp);
            if(temp>'Z')
                temp = temp-'Z'+'A'-1;
                str=['A' temp];
            end
            range = str;            
        end
        xlswrite(sprintf('data\\%s\\%d_%s_%d.xls',typeData,type,ticker,id_web)...
            , final_res,1,range);
        fprintf('... Done!');  
        x = 1;
    end
end
